use strict;
use warnings;

require "structure.pl";
require "game_data.pl";

# default data
my $file_structure = "game_structure";

# compilation data
my @src_files = ();
my $target;

# argument loop
while (my $arg = shift) {

	# new structure
	if ($arg eq "-s") {
		$file_structure = shift;
	}
	# open game data and check their structure
	elsif ($arg eq "-c") {

		# file to check
		my $file = shift;

		# structure to check against
		my $structure = game_structure_open($file_structure);
		if (!$structure) {
			printf("error reading structure: $file_structure\n");
			exit 0;
		}
		
		# get game data from file
		my $game_data = read_file($file);
		if (!$game_data) {
			printf("error reading game data: $file\n");
			exit 0;
		}

		# check data
		if (check_data($game_data, $structure)) {
			printf("file '$file' is structured based on $file_structure\n");
		}
		else {
			printf("file '$file' is NOT structure based on $file_structure\n");
		}

	} # -c : check data against structure
	elsif ($arg eq "-t") {
		$target = shift;
	}
	else {
		push @src_files, $arg;
	}

} # argument loop

if ($target eq "python") {

	if (@src_files <= 0) {
		printf("no source files given\n");
		exit 0;
	}

	# currently it only parses the first of the source files only
	my $game_data = read_file($src_files[0]);
	if (!$game_data) {
		printf("compilation error: $src_files[0]\n");
		exit 0;
	}

	# compile to python
	require("compile_to_python.pl");
	compile_to_python($game_data);

}
